﻿// -----------------------------------------------------------------------
// <copyright file="AbcBootstrapper.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Abc.Desktop
{
    using System.Windows;

    using Abc.Desktop.Adapters;
    using Abc.Desktop.ViewModels;
    using Abc.Desktop.Views;

    using DevExpress.Xpf.Bars;
    using DevExpress.Xpf.Docking;
    using DevExpress.Xpf.NavBar;
    using DevExpress.Xpf.Ribbon;

    using Microsoft.Practices.Prism.Events;
    using Microsoft.Practices.Prism.Modularity;
    using Microsoft.Practices.Prism.Regions;
    using Microsoft.Practices.Prism.UnityExtensions;
    using Microsoft.Practices.ServiceLocation;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class AbcBootstrapper : UnityBootstrapper
    {
        #region PRIVATE MEMBERS
        private RegionAdapterMappings m_mappings;
        #endregion

        #region UnityBootstrapper MEMBERS
        protected override DependencyObject CreateShell()
        {
            var shell = ServiceLocator.Current.GetInstance<RibbonShell>();
            shell.Container = Container;

            var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
            var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();

            shell.DataContext = new RibbonShellViewModel(eventAggregator) { RegionManager = regionManager };

            return shell;
        }

        protected override void InitializeShell()
        {
            Application.Current.MainWindow = (Window)Shell;
            Application.Current.MainWindow.Show();
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            //creando un catalogo a partir de la lectura de un directorio
            var catalog = new DirectoryModuleCatalog
                {
                   ModulePath = @"."
                };

            return catalog;
        }

        protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
        {
            m_mappings = base.ConfigureRegionAdapterMappings();
            if (m_mappings != null)
            {
                m_mappings.RegisterMapping(typeof(DockLayoutManager), ServiceLocator.Current.GetInstance<DockManagerAdapter>());
                m_mappings.RegisterMapping(typeof(LayoutPanel), ServiceLocator.Current.GetInstance<LayoutPanelAdapter>());
                m_mappings.RegisterMapping(typeof(NavBarControl), ServiceLocator.Current.GetInstance<NavBarControlAdapter>());
                m_mappings.RegisterMapping(typeof(RibbonControl), ServiceLocator.Current.GetInstance<DxRibbonControlAdapter>());
                m_mappings.RegisterMapping(typeof(BarManager), ServiceLocator.Current.GetInstance<BarManagerAdapter>());
            }
            return m_mappings;
        }
        #endregion
    }
}
